/*
 * 懒人CSS
 * CSS BY 梅川内酷
 * 2012-04-20——
*/
$(function(){
	//按需载入图片
	$("img[data-url]").lazyload({
		//threshold :400, //灵敏度
		effect:"fadeIn"
	});
	
	goTop();//返回顶部调用
	
	//判断IE6 hover事件
	if ($.browser.msie && ($.browser.version =="6.0") && !$.support.style) {
		$("body").addClass("ie6");
	}
	
});
//实例化
//var $browser = new browserFun(); //实例化浏览器版本判断	默认关闭

//原生js获取id tag
function $id(byid){ return document.getElementById(byid); }
function $tag(bytag){ return document.getElementsByTagName(bytag)[0]; }
//$id("navcon").onclick = function(){alert("000")}
//移除空元素
function removeNull(nullDom){
	$(nullDom+":empty").remove();
}
//改变类名函数
function changClass(thisDom,Event,thisClass){
	if(Event=="click"){
		$(thisDom).click(function(){
			$this = $(this);
			if(!$this.hasClass(thisClass||"cur")){
				$this.addClass(thisClass||"cur");
			}else{
				$this.removeClass(thisClass||"cur");	
			}
			return false;
		});
	}else{
		$(thisDom).on({
			'mouseenter': function(){
				$(this).addClass(thisClass||"cur");
			},
			'mouseleave': function(){
				$(this).removeClass(thisClass||"cur");
			}	
		});
	}
}
/*选项卡插件 作者：梅川内酷*/
;(function ($) {
	$.fn.lrTab = function (options) {
		var opts={
			Event:'click',
			callback:function(){}
		};
		$.extend(opts,options);
		this.on(opts.Event,'a',function(){
			var index =$(this).index();
			$(this).addClass("tabcur").siblings("a").removeClass("tabcur")
			.parent("div").next("div.tabcon").children("div").eq(index).show().siblings("div").hide();
			opts.callback();
			return false;
		});
	};
})(jQuery);
//placeholder插件 $("input.tinput").placeholder();
;(function ($) {
	$.fn.placeholder = function (options) {
		var opts={
			focusclass:'inputfocus'	//默认获得焦点时的样式，在写样式的时候用input:focus,.inputfocus{样式}组合使用
		};
		$.extend(opts,options);
		if(!isPlaceholder()){
			this.each(function(){
				var $this = $(this),$thisplaceholder = $this.attr("placeholder");
				$this.val($thisplaceholder);
				$this.focus(function(){ 
					if($this.val()==$thisplaceholder){
						$this.val("");
					}
					$this.addClass(opts.focusclass);
				}).blur(function(){
					if ($this.val() == ''){ 
						$this.val($thisplaceholder); 
					}
					$this.removeClass(opts.focusclass);
				});
			 });//each end
		}//if end
	};
	function isPlaceholder(){ 
		return 'placeholder' in document.createElement('input');  
	} 	
})(jQuery);
//返回顶部
 function goTop(H,T){
	if(!$("#gotop")[0]){
		$("body").append("<a href='javascript:;' id='gotop' class='gotop' onfocus='this.blur()'>^</a>");	
	}
	var $gotop = $("#gotop");
	/*不断检测滚动条是一个极大的性能消耗*/
	/*var $window = $(window);
	$window.on('scroll',function() {
		var w_scrollTop = $window.scrollTop();
		if(w_scrollTop > 150){
			$gotop.addClass("gotopshow");
		}
		else if(w_scrollTop < 200){
			$gotop.removeClass("gotopshow");
		}
	}); */
	$gotop.click(function() {
		$("html,body").animate({scrollTop:H||0},T||600);
		return false;
	});
 };
/*
 * 简单的向上滚动
 * 结构：<ul id="sshow"><li></li>...</ul><ul></ul>
 * 调用：$("#sshow").scrollUp()
*/ 
;(function($) {
	$.fn.scrollUp = function (options) {
		var opts={
			delay:2000
		};
		$.extend(opts,options);
		var x 	= this,
			y 	= x.next("ul"),
			lih = x.children("li:first").outerHeight()
			h 	= x.children("li").length * lih
		y.html(x.html());
		setTimeout(b,opts.delay);						
		function b(){	
			t = parseInt(x.css('top'));
			y.css('top',lih+"px");	
			x.animate({top: t - lih + 'px'},'slow');	
			if(Math.abs(t) == h-lih){ 					
				y.animate({top:'0px'},'slow');
				z=x;
				x=y;
				y=z;
			}
			setTimeout(b,opts.delay);
		}
	};
})(jQuery);
//懒人弹出层
/*
 * 参数说明：
 * contype:"url:post或者get?请求路径?发送请求数据?数据类型"
 * 其他参数，不解释
 * 此插件不支持IE6随屏滚动，IE6逐渐消亡中，不愿意专门为IE6增加额外的代码量
*/
;(function ($) {
    $.fn.lrsimpop = function (options) {
        var opts={
            styleclass:"lrpop_def",
			maskopa:0.3,
			brdopa:0.3,
			brd_w:'8',
			lrpop_w:"300",
			lrpop_h:"160",
			contype:"",
			lrpop_tit:"",
			lrpop_btns:"",
			mask_x:'yes',
			x_reload:false,		
			ajaxok:function(data){$lrpop_con.html(data);},
            callback:function(){}
        },_this=this;
        $.extend(opts,options);
		//插入html结构
		if(!$("#lrpop_warp")[0]){
			$("body").append("<div class='lrpop_warp' id='lrpop_warp'><div class='lrpop'><div class='lrpop_tit'><strong>弹出窗体</strong></div><a class='lrpop_x'>×</a><div class='lrpop_con' id='lrpop_con'>真遗憾！什么都没有发现。</div><div class='lrpop_btns'></div></div><div class='lrpop_brd'></div></div><div id='lrpop_mask'></div>");	
		}
		var $lrpop_mask 	= $("#lrpop_mask"),
			$lrpop_warp 	= $("#lrpop_warp"),
			$lrpop_lrpop 	= $lrpop_warp.children("div.lrpop"),
			$lrpop_tit 		= $lrpop_lrpop.children("div.lrpop_tit").children("strong"),
			$lrpop_con 		= $lrpop_lrpop.children("div.lrpop_con"),
			$lrpop_x 		= $lrpop_lrpop.children("a.lrpop_x"),
			$lrpop_btns 	= $lrpop_lrpop.children("div.lrpop_btns"),
			$lrpop_warp_w 	= opts.lrpop_w,$lrpop_warp_h = opts.lrpop_h;
		//背景遮罩和模拟半透明边框
		$lrpop_mask.css({
			opacity:opts.maskopa,height:$(document).height(),width:$(document).width()
		});
		$lrpop_warp.addClass(opts.styleclass).children("div.lrpop_brd").css({
			opacity:opts.brdopa,
			width:opts.lrpop_w*1+opts.brd_w*2,height:opts.lrpop_h*1+opts.brd_w*2,
			top:-opts.brd_w,left:-opts.brd_w
		});
		//设置标题和加载按钮
		if(opts.lrpop_tit){$lrpop_tit.html(opts.lrpop_tit);}else{$lrpop_tit.html(_this.text());}
		$lrpop_btns.html(opts.lrpop_btns);
		//show弹出层
		$.fn.lrsimpop.show($lrpop_warp_w,$lrpop_warp_h);
		//设置内容
		var content_array = opts.contype;
		contentType=content_array.substring(0,content_array.indexOf(":"));
		content=opts.contype.substring(content_array.indexOf(":")+1,content_array.length);
		switch(contentType){
  			case "html":
			$lrpop_con.html(content);
			break;
			case "id":
			$lrpop_con.html($("#"+content+"").html());
			break;
			case "url":
			var content_array=content.split("?");
			$lrpop_con.ajaxStart(function(){
				$(this).html("loading...");
			});
			$.ajax({
				type:content_array[0],
				url:content_array[1],
				data:content_array[2],
				dataType:""+content_array[3]+"",
				error:function(){
			  		$lrpop_con.html("很遗憾！没有载入成功...");
				},
				success:opts.ajaxok
			});
			break;
			case "iframe":
  			$lrpop_con.html("<iframe src=\""+content+"\" width=\"100%\" height=\""+(parseInt($lrpop_warp_h)-80)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
			break;
		}
		//回调
		opts.callback();
		//重设窗口时调整层位置
		$(window).resize(function(){
			var win_w = $(window).width();
			var win_h = $(window).height();
			var doc_h = $(document).height();
			$lrpop_mask.css({height:doc_h});
			$lrpop_warp.animate({
				left:win_w*0.5-($lrpop_warp_w)*0.5,
				top:win_h*0.5-($lrpop_warp_h)*0.5
			});
		});
		//单击关闭
		$lrpop_x.on('click', function(){
			$lrpop_mask.hide();
			$lrpop_warp.hide();
			$lrpop_con.html("");
			if(opts.x_reload==true){window.location.reload();}
		});
		//按钮
		$lrpop_btns.children("a").on('click', function(){
			$lrpop_x.trigger('click');
		});
		//单击遮罩关闭
		$lrpop_mask.on('click', function(){
			if(opts.mask_x=='yes'){
				$lrpop_x.trigger('click');
			}
		});
		
    };
   
	$.fn.lrsimpop.show = function(show_w,show_h){
		var win_w = $(window).width();
		var win_h = $(window).height();
		$("#lrpop_mask,#lrpop_warp").show().
		filter("#lrpop_warp").css({
			width:show_w,
			height:show_h,
			left:win_w*0.5-(show_w)*0.5,
			top:win_h*0.5-(show_h)*0.5
			//top:-show_h-100				//初始把top负出去下面要做自定义动画用
		}).animate({
			//top:win_h*0.5-(show_h)*0.5
		});
		
    };
   
})(jQuery);
/*
 * lazy loading images Version:  1.8.4 http://www.appelsiini.net/projects/lazyload
 * <img class="lazy" src="img/grey.gif" data-original="img/example.jpg" width="640" height="480">
 * $("img.lazy").lazyload({ threshold : 200 });
*/
;(function(a,b,c,d){var e=a(b);a.fn.lazyload=function(c){function i(){var b=0;f.each(function(){var c=a(this);if(h.skip_invisible&&!c.is(":visible"))return;if(!a.abovethetop(this,h)&&!a.leftofbegin(this,h))if(!a.belowthefold(this,h)&&!a.rightoffold(this,h))c.trigger("appear"),b=0;else if(++b>h.failure_limit)return!1})}var f=this,g,h={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:b,data_attribute:"url",skip_invisible:!0,appear:null,load:null};return c&&(d!==c.failurelimit&&(c.failure_limit=c.failurelimit,delete c.failurelimit),d!==c.effectspeed&&(c.effect_speed=c.effectspeed,delete c.effectspeed),a.extend(h,c)),g=h.container===d||h.container===b?e:a(h.container),0===h.event.indexOf("scroll")&&g.bind(h.event,function(a){return i()}),this.each(function(){var b=this,c=a(b);b.loaded=!1,c.one("appear",function(){if(!this.loaded){if(h.appear){var d=f.length;h.appear.call(b,d,h)}a("<img />").bind("load",function(){c.hide().attr("src",c.data(h.data_attribute))[h.effect](h.effect_speed),b.loaded=!0;var d=a.grep(f,function(a){return!a.loaded});f=a(d);if(h.load){var e=f.length;h.load.call(b,e,h)}}).attr("src",c.data(h.data_attribute))}}),0!==h.event.indexOf("scroll")&&c.bind(h.event,function(a){b.loaded||c.trigger("appear")})}),e.bind("resize",function(a){i()}),/iphone|ipod|ipad.*os 5/gi.test(navigator.appVersion)&&e.bind("pageshow",function(b){b.originalEvent.persisted&&f.each(function(){a(this).trigger("appear")})}),a(b).load(function(){i()}),this},a.belowthefold=function(c,f){var g;return f.container===d||f.container===b?g=e.height()+e.scrollTop():g=a(f.container).offset().top+a(f.container).height(),g<=a(c).offset().top-f.threshold},a.rightoffold=function(c,f){var g;return f.container===d||f.container===b?g=e.width()+e.scrollLeft():g=a(f.container).offset().left+a(f.container).width(),g<=a(c).offset().left-f.threshold},a.abovethetop=function(c,f){var g;return f.container===d||f.container===b?g=e.scrollTop():g=a(f.container).offset().top,g>=a(c).offset().top+f.threshold+a(c).height()},a.leftofbegin=function(c,f){var g;return f.container===d||f.container===b?g=e.scrollLeft():g=a(f.container).offset().left,g>=a(c).offset().left+f.threshold+a(c).width()},a.inviewport=function(b,c){return!a.rightoffold(b,c)&&!a.leftofbegin(b,c)&&!a.belowthefold(b,c)&&!a.abovethetop(b,c)},a.extend(a.expr[":"],{"below-the-fold":function(b){return a.belowthefold(b,{threshold:0})},"above-the-top":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-screen":function(b){return a.rightoffold(b,{threshold:0})},"left-of-screen":function(b){return!a.rightoffold(b,{threshold:0})},"in-viewport":function(b){return a.inviewport(b,{threshold:0})},"above-the-fold":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-fold":function(b){return a.rightoffold(b,{threshold:0})},"left-of-fold":function(b){return!a.rightoffold(b,{threshold:0})}})})(jQuery,window,document);

//浏览器版本判断 使用方法： var $browser = new browserFun();	alert($browser.firefox);
function browserFun(){         	
	var browserName=navigator.userAgent.toLowerCase();
	this.ver = (browserName.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [0, '0'])[1];  
	this.msie = /msie/i.test(browserName) && !/opera/.test(browserName);
	this.firefox = /firefox/i.test(browserName);
	this.chrome = /chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName);
	this.opera = /opera/i.test(browserName);
	this.safari = /webkit/i.test(browserName) &&!(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName));
};
//去空格
String.prototype.trim = function (str) {
	return this.replace(/(^\s+)|(\s+$)/g, "");
};
//加入收藏夹
function addFav() {
	if (document.all) {
		window.external.addFavorite(document.location.href,document.title);
	}
	else if (window.sidebar) {
		window.sidebar.addPanel(document.title,document.location.href,"")
	}
};
if($id("addfav")){
	$id("addfav").onclick = function(){
		addFav();
	}
};


